package com.kaola.service.impl;

import java.util.List;
import java.util.regex.Pattern;

import com.kaola.dao.UserDAO;
import com.kaola.pojo.User;
import com.kaola.service.UserService;

public class UserServiceImpl implements UserService {
	
	private UserDAO userDAO;
	
	public UserDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	public void create(User user) {
		userDAO.create(user);
	}

	public User show(int id) {
		return userDAO.show(id);
	}

	public User get(String account) {
		return userDAO.get(account);
	}
	
	public List<User> list() {
		return userDAO.list();
	}

	public boolean validate(User user) {
		User u = userDAO.get(user.getAccount());
		if (u != null) {
			if (u.getPassword().equals(user.getPassword())
					&& u.getAccount().equals(user.getAccount())) {
				return true;
			}
		}
		return false;
	}

	public boolean exist(String account) {
		if (userDAO.get(account) != null) {
			return true;
		}
		return false;
	}
}
